package com.example.myapplication;


import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;


import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {
    private ViewPager viewPager;
    private List<Fragment> fragmentList=new ArrayList<>();
    private NewsFragmentAdapter newsFragmentAdapter;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        initFragmentList();
        initViews();
    }

    private void initFragmentList() {
        NewsFragment newsFragment1=new NewsFragment();
        newsFragment1.setType("top");
        NewsFragment newsFragment2=new NewsFragment();
        newsFragment2.setType("keji");
        NewsFragment newsFragment3=new NewsFragment();
        newsFragment3.setType("yule");
        NewsFragment newsFragment4=new NewsFragment();
        newsFragment4.setType("tiyu");

        fragmentList.add(newsFragment1);
        fragmentList.add(newsFragment2);
        fragmentList.add(newsFragment3);
        fragmentList.add(newsFragment4);

    }

    private void initViews() {
        viewPager = findViewById(R.id.news_viewPager);
        viewPager.setOffscreenPageLimit(6);
        newsFragmentAdapter =  new NewsFragmentAdapter(getSupportFragmentManager(), fragmentList);
        viewPager.setAdapter(newsFragmentAdapter);
    }
}
